/**
 * @author Chengzi Xu
 */

package cn.edu.sjtu.stap.sdg.internal;

// import org.aspectj.ajdt.internal.core.builder.AjBuildConfig;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;

import cn.edu.sjtu.stap.cfg.internal.*;
import cn.edu.sjtu.stap.sdg.builder.ISdgBuilder;
import cn.edu.sjtu.stap.cfg.builder.*;
import cn.edu.sjtu.stap.cg.builder.*;
import cn.edu.sjtu.stap.sdg.*;
import cn.edu.sjtu.stap.sdg.builder.ISdgBuilderFactory;
import cn.edu.sjtu.stap.util.AstArray;

public privileged aspect IntraSdgBuilderAdapter {

    before(CompilationUnitDeclaration u, int index) : AstFetcher.astFetcherPc(u, index) {
        ICfgBuilder cfgBuilder = Initializer.getCfgBuilder();
        ISdgBuilder sdgBuilder = Initializer.getSdgBuilder();

        sdgBuilder.buildIntraSdg(cfgBuilder);

        // output the intraCFG
//        SDGResultOutput.getInstance().writeIntraproceduralCfg(
//                SDGResultOutput.getFileOutputStream("ResultOfIntraCFG"),
//                cfgBuilder.getIntraModuleCfgs());

//         //output the IntraSDG
//        SDGResultOutput.getInstance().writeSdg(
//                SDGResultOutput.getFileOutputStream("ResultOfIntraSDG"),
//                sdgBuilder.getIntraSdgs());
        
        Initializer.out.writeLine("IntraSDGs Start:------------------------------------------");
        Initializer.out.writeLine("**********************************************************");
        Initializer.out.writeIntraSdg(sdgBuilder.getIntraSdgs());

        SDGResultOutput.close();
//        AstArray.getInstance().tidyUp();
    }

//    private static ICfgBuilder getCfgBuilder() {
//        return ICfgBuilderFactory.getDefaultCfgBuilderFactory().getCfgBuilder();
//    }

    private static ISdgBuilder getSdgBuilder() {
        return ISdgBuilderFactory.getDefaultSdgBuilderFactory().getSdgBuilder();
    }
    
//    /**
//     * this method can not deleted
//     */
//    private static ICgBuilder getCgBuilder() {
//        return ICgBuilderFactory.getDefaultCgBuilderFactory().getCgBuilder();
//    }

}
